package com.ssmeasy.jdgl.controller;

import com.ssmeasy.jdgl.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * @api {post} /orders/openRoom/secure 开房
     * @apiName openRoom
     * @apiGroup Orders
     * @apiVersion 0.1.0
     *
     * @apiDescription 开房
     *
     * @apiParam {int} id  房间号
     * @apiParam {String} name  姓名
     * @apiParam {String} idcard  身份证号码
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "res":true
     * }
     *
     * @apiErrorExample {json} Error-Response:
     *  HTTP/1.1 200 OK
     *  {
     *  	"res":false
     *  }
     */
    @RequestMapping("/openRoom/secure")
    @ResponseBody
    public Map<String,Boolean> openRoom(int id,String name,String idcard){

        //返回值Map
        Map<String,Boolean> result = new HashMap<>();


        try {
            ordersService.openRoom(id,name,idcard);
            result.put("res",true);
        }catch (Exception e){
            e.printStackTrace();
            result.put("res",false);
        }

        return result;

    }



    /**
     * @api {post} /orders/exitRoom/secure 退房
     * @apiName exitRoom
     * @apiGroup Orders
     * @apiVersion 0.1.0
     *
     * @apiDescription 退房
     *
     * @apiParam {int} id  房间号
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "res":true
     * }
     *
     * @apiErrorExample {json} Error-Response:
     *  HTTP/1.1 200 OK
     *  {
     *  	"res":false
     *  }
     */
    @RequestMapping("/exitRoom/secure")
    @ResponseBody
    public Map<String,Boolean> exitRoom(int id){

        //返回值Map
        Map<String,Boolean> result = new HashMap<>();


        try {
            ordersService.exitRoom(id);
            result.put("res",true);
        }catch (Exception e){
            e.printStackTrace();
            result.put("res",false);
        }

        return result;

    }




}
